#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2008-6-25 上午02:43:12 
#Create By: Fla.sam
#
#DESC: google app engine blog templatetags
#
#-------------------------------------------------

from blog import models
from django import template
from django.utils.html import conditional_escape
from django.utils.http import urlquote
from django.utils.safestring import mark_safe
from google.appengine.ext import db

register = template.Library()

@register.filter
def get_article_tags( value ):
    
    tags = db.get( value.article_tags )
    esc = conditional_escape
    _template = ''
    for tag in tags:
        _template += '''<a href=/blog/tag/%s>%s</a>&nbsp;''' % ( urlquote( tag.tag_name ), esc( tag.tag_name ) )
    return mark_safe( _template )

@register.filter
def get_tag_rating_class( value ):
    _t_rating = value.tag_rating
    
    #get max and min rating
    _tag_all_instances = models.Tag().all().order( 'tag_rating' )
    _min_tag_rating = _tag_all_instances.fetch( -1 )
    _max_tag_rating = _tag_all_instances.fetch( 0 )
    
    